-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up IP pool resolution from NameOrId
#5674
Conversation
@@ -50,7 +50,6 @@ use omicron_common::api::external::Error; | |||
use omicron_common::api::external::IdentityMetadataCreateParams; | |||
use omicron_common::api::external::ListResultVec; | |||
use omicron_common::api::external::LookupResult; | |||
use omicron_common::api::external::NameOrId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting this out of here is a good thing
@@ -15,7 +15,6 @@ use diesel::{ExpressionMethods, QueryDsl, SelectableHelper}; | |||
use nexus_db_model::IncompleteNetworkInterface; | |||
use nexus_db_model::Probe; | |||
use nexus_db_model::VpcSubnet; | |||
use nexus_types::external_api::params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting this out of here is a good thing
let (.., pool) = LookupPath::new(opctx, &self) | ||
.ip_pool_id(authz_pool.id()) | ||
.fetch_for(authz::Action::CreateChild) | ||
.await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fetch was not necessary at all — replaced by opctx.authorize
call in resolve_pool_for_allocation
.0, | ||
), | ||
None => None, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While overall I think this PR is a net improvement already, I might try to roll up this logic further with what's in resolve_pool_for_allocation
because it is awkward to split up this part of the resolution of the pool from the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning that up! LGTM w/ one suggestion
@@ -84,33 +83,14 @@ impl DataStore { | |||
opctx: &OpContext, | |||
ip_id: Uuid, | |||
probe_id: Uuid, | |||
pool_name: Option<NameOrId>, | |||
pool: Option<authz::IpPool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind giving allocate_instance_snat_ip
similar treatment so we're consistent across everything here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. I didn’t look hard enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followup to #5660, specifically #5660 (comment). I didn't do it quite as suggested, basically because I think datastore functions being aware of
NameOrId
is a bad thing as that is, to me, an API concept that we should have resolved to something real by the time we get to the datastore functions. This is still a little odd and a little redundant, but it is cleaner and more consistent.In each case (floating IP create, probe create, instance ephemeral IP allocated) we are doing the following:
Option<NameOrId>
intoOption<authz::IpPool>
(this is a DB query of course)resolve_pool_for_allocation
, whicha. If a pool is specified, makes sure it's linked to the current silo, otherwise 404
b. If a pool is not specified, get the default pool for the current silo
c. Either way, make sure we have
CreateChild
on the pool (we always do if we're authenticated at all, but that could change in the future)authz::IpPool
and can get on with whatever allocation